package com.ren.weibo.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ren.weibo.base.response.JsonResult;
import com.ren.weibo.base.response.StatusCode;
import com.ren.weibo.mapper.CommentMapper;
import com.ren.weibo.pojo.dto.CommentParam;
import com.ren.weibo.pojo.entity.Comment;
import com.ren.weibo.pojo.vo.CommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Slf4j
@Api(tags = "评论模块")
@RestController
@RequestMapping("/v1/comment")
public class CommentController {
    @Autowired
    private CommentMapper commentMapper;

    @ApiOperation("发布评论")
    @ApiOperationSupport(order = 10)
    @PostMapping("/insert")
    public JsonResult insert(@RequestBody CommentParam commentParam) {
        Comment comment = new Comment();
        comment.setContent(commentParam.getContent());
        comment.setCreateTime(new Date());
        comment.setUserId(commentParam.getUserId());

        commentMapper.add(comment);
        return JsonResult.ok();
    }

    @ApiOperation("获取评论列表")
    @ApiOperationSupport(order = 20)
    @GetMapping("/selectByWeiboId")
    public JsonResult selectByWeiboId(Integer weiboId) {
        List<CommentVO> commentVOS = commentMapper.selectByWeiboId(weiboId);
        return new JsonResult(StatusCode.OPERATION_SUCCESS, commentVOS);

    }
}
